//
//  TaskController.m
//  Qzone
//
//  Created by 王昭的Mac Air on 2018/6/12.
//  Copyright © 2018年 zhang. All rights reserved.
//

#import "TaskController.h"
#import "TaskListCell.h"

@interface TaskController () <UITableViewDelegate, UITableViewDataSource>

@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, copy) NSArray *titleArr;

@end

@implementation TaskController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.navigationItem.title = @"每日任务";
    [self setNavigationBar];
    self.navigationController.navigationBarHidden = NO;
    
    _titleArr = @[@{@"title":@"发表评论", @"content":@"评论他人分享的内容（头像、图片、日志、皮肤）达到20条", @"gol":@"100", @"dia":@"20", @"exp":@"20"},
                  @{@"title":@"关注好友", @"content":@"关注5个新的好友，即可领取该奖励！当前进度0/5", @"gol":@"100", @"dia":@"20", @"exp":@"20"},
                  @{@"title":@"空间留言", @"content":@"去朋友的个人空间留言10条，完成后即可领取该任务奖励！", @"gol":@"100", @"dia":@"20", @"exp":@"20"},
                  @{@"title":@"发布头像", @"content":@"发布二篇头像，审核通过后即可领取相关奖励", @"gol":@"100", @"dia":@"20", @"exp":@"20"},
                  @{@"title":@"发布图片", @"content":@"发布二篇图片，审核通过后即可领取相关奖励", @"gol":@"100", @"dia":@"20", @"exp":@"20"},
                  @{@"title":@"回复帖子", @"content":@"在讨论组回复他人发布的帖子（10个回复）即可领取该任务奖励", @"gol":@"100", @"dia":@"20", @"exp":@"20"}];
    
    [self.view addSubview:self.tableView];
}

#pragma mark - init
- (UITableView *)tableView
{
    if (!_tableView) {
        _tableView = [[UITableView alloc] initWithFrame:self.view.bounds style:UITableViewStyleGrouped];
        _tableView.height -= NavBarHeight;
        _tableView.backgroundColor = UIColorFromRGB(BgSystemColor);
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}


#pragma mark - tableView delegate
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return _titleArr.count;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 1;
}

- (CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section
{
    return 10.0f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForFooterInSection:(NSInteger)section
{
    return 0.1f;
}

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return [TaskListCell getCellHeightWithData:_titleArr[indexPath.section]];
}

- (UIView *)tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section
{
    return [[UIView alloc] init];
}

- (UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc] init];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *identifier = @"TaskListCellIdentifier";
    TaskListCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell) {
        cell = [[TaskListCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    [cell dataWithDictionary:_titleArr[indexPath.section]];
    [cell.statusBtn addTarget:self action:@selector(taskAction) forControlEvents:UIControlEventTouchUpInside];
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
}

- (void)taskAction
{
    [[AlertUtil shareInstance] showAlert:nil message:@"领取奖励" cancelTitle:nil titleArray:nil viewController:self confirm:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
